package com.xkdx.caipiao;

import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xkdx.caipiao.cost.CostRechargeActivty;
import com.xkdx.caipiao.listener.OnAlertDialogOkListener;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.my.FlowRechargeActivity;
import com.xkdx.caipiao.presistence.login.Login;
import com.xkdx.caipiao.presistence.login.LoginInfo;
import com.xkdx.caipiao.wiget.MyAlertDialog;

public class HomePageActivity extends ThreadActivity implements
		OnClickListener, OnAlertDialogOkListener {
	private TextView tv_wode;
	public static LoginInfo loginInfo;
	private RelativeLayout goToWifi, goToCaiPiao, goToPhone,goToShop;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home_update_caipiao);
		init();
		loginInfo = getLoginInfo();
		if (loginInfo != null
				&& !(TextUtils.isEmpty(loginInfo.getLogintoken()))) {
//			tv_wode.setText("我的逛逛");
		}
	}

	private void init() {
		goToWifi = (RelativeLayout) findViewById(R.id.go_to_wifi);
		goToCaiPiao = (RelativeLayout) findViewById(R.id.go_to_caipiao);
		goToPhone = (RelativeLayout) findViewById(R.id.go_to_phone);
		goToShop = (RelativeLayout) findViewById(R.id.go_to_shop);
		goToWifi.setOnClickListener(this);
		goToCaiPiao.setOnClickListener(this);
		goToPhone.setOnClickListener(this);
		goToShop.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.go_to_wifi:
			startIntent(FlowRechargeActivity.class);
			break;
		case R.id.go_to_caipiao:
			startIntent(MainTabActivity.class);
			break;
		case R.id.go_to_phone:
			startIntent(CostRechargeActivty.class);
			break;
		case R.id.go_to_shop:
			startIntent(ShopActivity.class);
			break;

		default:
			break;
		}
//		case R.id.ll_mygg:
//
//			loginInfo = getLoginInfo();
//			if (loginInfo != null
//					&& !(TextUtils.isEmpty(loginInfo.getLogintoken()))) {
//				Intent inten2 = new Intent(this, MyStrollActivity.class);
//				startActivity(inten2);
//			} else {
//				Intent inten3 = new Intent(this, Login.class);
//				startActivity(inten3);
//			}
//
//			break;

		
	}

	

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {

	}

	@Override
	public void startThread() {
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			if (event.getAction() == KeyEvent.ACTION_DOWN
					&& event.getRepeatCount() == 0) {
				showTips();
			}
			return true;
		}
		return super.dispatchKeyEvent(event);
	}

	private void showTips() {

		MyAlertDialog.creatAlertDialog(HomePageActivity.this, "退出提示",
				"确定退出逛逛生活?");
		MyAlertDialog.setOnAlertDialogOklistener(this);

	}

	@Override
	public void onBackClick(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onResume() {
		super.onResume();
		loginInfo = getLoginInfo();
		if (loginInfo != null
				&& !(TextUtils.isEmpty(loginInfo.getLogintoken()))) {
			tv_wode.setText("我的逛逛");
		}
	}

	@Override
	public void handleOkClick() {
		System.exit(0);
		android.os.Process.killProcess(android.os.Process.myPid());

	}

	@Override
	public void handleDismissClick() {
		// TODO Auto-generated method stub

	}
	private void startIntent(Class a) {
		Intent inten = new Intent(HomePageActivity.this, a);
		startActivity(inten);
	}

}
